import { ref } from 'vue'
import { defineStore } from 'pinia'
import { routerArray } from "@/router/index";
import { getUserInfo } from "@/api/authorityApi/authorityApi.js"
export const StoreUsers = defineStore('StoreUsers', () => {
    let userRouter = ref([]) // 用户列表
    let getPermission = async () => {
        if (localStorage.getItem('permissionList')) return
        await getUserInfo().then((res: any) => {
            localStorage.setItem("permissionList", JSON.stringify(res.data.roles.menus))
            userRouter.value = res.data.roles.menus
            // 过滤出路由
            let router = routerArray.filter((item: any) => {
                return res.data.roles.menus.includes(item.name)
            })
            router.unshift(routerArray[0])
            localStorage.setItem("routerMap", JSON.stringify(router))
        })
    }
    return { getPermission, userRouter }
})
